#include <stdio.h>
#include <unistd.h>
#include "ohos_init.h"
#include "ohos_types.h"
#include "cmsis_os2.h"
#include "iot_watchdog.h"
#include "hi_watchdog.h"

static void WDTTask(void)
{
    unsigned short num = 0;
    hi_watchdog_set_timeout(10000);
    IoTWatchDogEnable();
    while (1)
    {
        num++; // 模拟耗时操作
        // 取消下面的注释即可喂狗
        // if (num == 0) // 每当 num 变量溢出时喂一次狗
        //     IoTWatchDogKick();
    }
}

void WDTExample(void)
{
    osThreadAttr_t attr;
    attr.name = "WDTTask";
    attr.attr_bits = 0U;
    attr.cb_mem = NULL;
    attr.cb_size = 0U;
    attr.stack_mem = NULL;
    attr.stack_size = 512;
    attr.priority = osPriorityNormal;
    if (osThreadNew((osThreadFunc_t) WDTTask, NULL, &attr) == NULL)
    {
        printf("Failed to create WDTTask!\n");
    }
}

SYS_RUN(WDTExample);
